﻿ #if UNITY_EDITOR
using UnityEditor;
using UnityEngine;

namespace AutoConstraintDressed
{
    public class ConstraintDressed : ConstraintDressedUtils
    {
        private Vector2 mainScrollPos;
        private GameObject avatar, cloth;
        

        [MenuItem("Custom/约束穿衣", false, 1)]
        static void ShowWindow()
        {
            var window = GetWindow(typeof(ConstraintDressed),true, "VRC一键约束穿衣");
            window.Show();
        }
        private void OnGUI()
        {
             
            mainScrollPos = GUILayout.BeginScrollView(mainScrollPos);
            GUILayout.Space(10);
            GUI.skin.label.fontSize = 24;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("约束穿衣");
            GUI.skin.label.fontSize = 12;
            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            GUILayout.Label("by:海藻");
            GUILayout.Label("GUI reference to:如梦  vrc工具箱");
            GUILayout.Space(10);
            
            avatar = EditorGUILayout.ObjectField("选择模型", avatar, typeof(GameObject), true) as GameObject;
            using (var check = new EditorGUI.ChangeCheckScope())
            {
                cloth = EditorGUILayout.ObjectField("衣服", cloth, typeof(GameObject), true) as GameObject;
                if(check.changed)
                {
                    aliasCloth = cloth.name;
                }
            }
            GUILayout.Space(10);
            if (avatar == null) EditorGUILayout.HelpBox("请添加模型", MessageType.Warning);
            if (cloth == null) EditorGUILayout.HelpBox("请添加衣服", MessageType.Warning);
            GUILayout.Label("骨骼助记名：");
            aliasCloth = GUILayout.TextField(aliasCloth,10);
            isIgnoreCase = GUILayout.Toggle(isIgnoreCase, "无视大小写匹配：");
            isSubString = GUILayout.Toggle(isSubString, "子字符串匹配：");
            if(isSubString)EditorGUILayout.HelpBox("可能会出错，请自行确认是否有相似骨骼名称", MessageType.Warning);
            isDeleteOldConstraint = GUILayout.Toggle(isDeleteOldConstraint, "是否原有ParentConstraint组件：");

            if (GUILayout.Button("一键穿衣") && avatar != null && cloth != null)
            {
                AutoConstraintDressed(avatar, cloth);
            }
            if(GUILayout.Button("移除约束组件")&&cloth!=null)
            {
                RemoveAllComponent(cloth);
            }
            GUILayout.Space(10);
            GUILayout.EndScrollView();
        }
    }
}
#endif